/**
 * Created by baiguiren on 1/23/17.
 */

let async = require('async');

let count = 1;
async.forever(
  function (next) {
    // next is suitable for passing to things that need a callback(err [, whatever]);
    // it will result in this function being called again.
    console.log(count++);
    count <= 5 ? next() : next('finished');
  },
  function (err) {
    // if next is called with a value in its first parameter, it will appear
    // in here as 'err', and execution will stop
    console.log('err:', err);
  }
);